﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.SharePoint;

namespace Ko2.Portal.SP_List
{

    public static class SPListItemLinkHelper
    {

        /// <summary>
        /// Returns the value of an Url-Field.
        /// </summary>
        public static string GetFieldValueUrl(this SPListItem item, string fieldName)
        {
            if (item != null)
            {
                SPFieldUrlValue urlValue =
                    new SPFieldUrlValue(item[fieldName] as string);
                return urlValue.Url;
            }
            else
            {
                return string.Empty;
            }
        }

        /// <summary>
        /// Sets the value of an URL-Field.
        /// </summary>
        public static void SetFieldValueUrl(this SPListItem item, string fieldName, string url, string description)
        {
            if (item != null)
            {
                item[fieldName] =
                    new SPFieldUrlValue()
                    {
                        Description = description,
                        Url = url
                    };
            }
        }

    }

}
